package com.example.javabasic.suanfa.jiandan.翻转链表;

/**
 * @description 翻转链表2
 * @Author Lin FuYuan
 * @date 2021/5/12
 */
public class Reverse2 {

    public static void main(String[] args) {
        Node node = new Node(1);
        int i = 1;
        Node noder = node;
        while (i < 6) {
            Node nn = new Node(++i);
            noder.setNext(nn);
            noder = nn;
        }
        //1,2,3,4,5,6,null
        //2,1,4,3,6,5,null
        test1(node);

        System.out.println(node);
    }



    public static void test1(Node node ){
        Node a = node ;
        Node b = node.getNext();
        Node c = node.getNext().getNext();

        while(a!=null &&b !=null ){
            //a指向c
            a.setNext( c);
            //b指向a
            b.setNext(a);
            a = c;
            if(a==null){
                break;
            }
            b = c.getNext();
            if(b==null){
                break;
            }
            c = c.getNext().getNext();
        }

    }




}
